package dasregistry;

import java.rmi.RemoteException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import javax.xml.rpc.ServiceException;

import org.apache.axis.AxisFault;

import uk.ac.ebi.www.ontology_lookup.OntologyQuery.OntologyQuerySoapBindingStub;
import uk.ac.ebi.www.ontology_lookup.OntologyQuery.Query;
import uk.ac.ebi.www.ontology_lookup.OntologyQuery.QueryService;
import uk.ac.ebi.www.ontology_lookup.OntologyQuery.QueryServiceLocator;

public class DasRegistryOntologyLookUp {

	private Query query = null;

	public static void main(String args[]) {
		DasRegistryOntologyLookUp lookup = new DasRegistryOntologyLookUp();

	}

	public DasRegistryOntologyLookUp() {

		init();
		this.exists("SO:0001077");
		
		


	}

	private void init() {
		QueryService locator = new QueryServiceLocator();

		this.query = null;
		try {
			query = locator.getOntologyQuery();
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		HashMap map = null;
		try {
			map = query.getOntologyNames();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Collection collection = map.keySet();
		Iterator it = collection.iterator();
		System.out.println("initializing web service for ontologies");
		while (it.hasNext()) {
			String ontKey = (String) it.next();
			System.out.println("Ontology Key: " + ontKey+" value: "+map.get(ontKey));
			
		}
	}

	
	public boolean exists(String id){
		boolean exists= false;
		if(this.query==null){
			this.init();
		}
		try {
			String term=query.getTermById(id, "BS");
			System.out.println("term found="+term);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return exists; 
	}
}
